package com.zhou.player;

import com.zhou.exceptions.TtsException;

import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.IOException;


/**
 * @author lcz
 * @desc 我球员
 * @mail lcz_0130@163.com
 * @date 2024/04/30
 */

public interface MyPlayer {
    static MyPlayer getInstance(String path) {
        String suffix = path.substring(path.lastIndexOf("."));
        switch (suffix) {
            case ".mp3":
                return new Mp3Player();
            case ".pcm":
                return new PcmPlayer();
            default:
                throw TtsException.of("不支持的音频文件：" + suffix);
        }
    }

    /**
     * 播放音频
     *
     * @param path
     * @throws IOException
     * @throws UnsupportedAudioFileException
     */
    void play(String path) throws IOException, UnsupportedAudioFileException;
}
